home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Fixation 1.3
/
connexions.c
< prev
next >
Wrap
Text File
|
1996-04-10
|
3KB
|
127 lines
// connexions.c
#include <string.h>
#include "mytypes.h"
#include "globals.h"
#include "error.h"
#include "util.h"
#include "outgoing.h"
#include "connexions.h"
#include "window.h"
#include "preffile.h"
#include "game.h"
#include "tcpstuff.h"
ulong curTime = 0;
Boolean gInTheThick = false, gLookinAtStorage;
Boolean gPlaying = false, gSetStyle, gNeedPassword, gSentAlarm;
Handle gSound1, gSound2, gSound3, gSound4;
static short oldStati[kMaxStreams];
void
ConnInit(void)
{
gSound1 = GetResource('snd ', 128);
gSound2 = GetResource('snd ', 129);
gSound3 = GetResource('snd ', 130);
gSound4 = GetResource('snd ', 131);
verify(gSound1); verify(gSound2);
verify(gSound3); verify(gSound4);
short nnn;
for (nnn=0;nnn<kMaxStreams;nnn++)
oldStati[nnn] = kStatClosed;
}
void
ResetConnectionInfo(void)
{
short nnn;
for (nnn=0;nnn<kMaxStreams;nnn++)
oldStati[nnn] = kStatClosed;
}
static void
WatchStati(void)
{
short nnn;
for (nnn=0;nnn<kMaxStreams;nnn++) {
if (oldStati[nnn] != kStatOpen && nexStatus[nnn] == kStatOpen) {
// tprintf("Connected to server on stream %d\r", nnn);
tprintf("Connected to server\r");
StartPlaying();
}
if (oldStati[nnn] != kStatClosed && nexStatus[nnn] == kStatClosed) {
StopPlaying();
// tprintf("Connection closed on stream %d\r", nnn);
}
oldStati[nnn] = nexStatus[nnn]; // please to remember
}
}
void
ConnIdle(void)
{
WatchStati();
}
void OpenTalker(void)
{
char adname[256];
char name[256], password[256];
unsigned long addr;
unsigned short port;
long passport = 5000;
memcpy(name, gPrefs.name, kPlayerNameLength);
memcpy(password, gPrefs.password, kPlayerNameLength);
memcpy(adname, gPrefs.serverAddress, 256);
passport = gPrefs.port;
if (!GetAnAddress(name, password, adname, &passport))
return;
port = passport;
ResetConnectionInfo();
// remember the stuff they chose
memcpy(gPrefs.serverAddress, adname, 256);
memcpy(gPrefs.name, name, kPlayerNameLength);
gPrefs.name[kPlayerNameLength-1] = 0;
memcpy(gPrefs.password, password, kPlayerNameLength);
gPrefs.password[kPlayerNameLength-1] = 0;
gPrefs.port = passport;
if (NetNameToAddr(adname, &addr, &port))
tprintf("Can't resolve.\r");
else {
tprintf("trying "); PrintAddress(addr); tprintf(" : %u . . .\r", port);
if (PrepareTheWay(0)) {
VDebugStr("Error creating stream.");
return; // failed to create
}
if (DoTCPActiveOpen(0, addr, port)) {
// VDebugStr("Error opening connection.");
tprintf("Error opening connection -- is anybody out there?\r");
// close the stream
ReleaseStreams();
}
else
tprintf("Opened connection.\r");
}
}
void
Audi5000(short stream)
{
// SendImQuitting();
bprintf("quit\r");
ReleaseStreams();
}